typedef int STDataType;

class Stack {
public:
    Stack(int capacity = 4) {
        _arr = (STDataType*)malloc(sizeof(STDataType) * capacity);
        if (_arr == nullptr) {
            perror("malloc fail");
            return;
        }
        _top = 0;
        _capacity = capacity;
    }

    void push(STDataType x) {
        _arr[_top] = x;
        _top++;
    }

    void pop() {
        _top--;
    }

    STDataType top() {
        return _arr[_top - 1];
    }

    bool empty() {
        return _top == 0;
    }

    int STSize() {
        return _top;
    }

    ~Stack() {
        if (_arr) {
            free(_arr);
            _arr = nullptr;
            _top = 0;
            _capacity = 0;
        }
    }

private:
    STDataType* _arr;
    int _capacity;
    int _top;
};

class MyQueue {
private:
    Stack A;
    Stack B;
public:
    MyQueue() {}

    void push(int x) {
        A.push(x);
    }

    int pop() {
        int peek = this->peek();
        B.pop();
        return peek;
    }

    int peek() {
        if (!B.empty()) return B.top();
        if (A.empty()) return -1;
        while (!A.empty()) {
            B.push(A.top()), A.pop();
        }
        int res = B.top();
        return res;
    }

    bool empty() {
        return A.empty() && B.empty();
    }
};
